
import {inject, observer} from "mobx-react";
import {toJS} from 'mobx';
import {
  WeaDialog,
  WeaLocaleProvider,
  WeaRightMenu
} from 'ecCom';
import isEmpty from "lodash/isEmpty";
import CubeLayout from "../../../../govern/components/E9/cubeLayout";
const getLabel = WeaLocaleProvider.getLabel;

@inject('blogSetting')
@observer
export default class PreviewModule extends React.Component {




  initCallBack=()=>{

  }



  doCancel = () => {
    const {blogSetting} = this.props;
    blogSetting.setModuleState({showPreview: false, richTextValue: ''});
    blogSetting.cubeLayoutParame = {};
    blogSetting.partid = 0;
  }

  render() {
    const {blogSetting} = this.props;

    const {cubeLayoutParame,partid,getCardStorefun} = blogSetting;

    const {showPreview, richTextValue} = toJS(blogSetting.moduleStatus);
    const title = getLabel(31568, '模版预览');
    const collectParams={
      favname: title,
      favouritetype: 1,
      objid:0,
      link:'wui/engine.html#/blogengine/setting',
      importantlevel: 1,
    };


    let cubeFlags= false;
    if(!isEmpty(cubeLayoutParame)){
      cubeFlags  = Object.keys(toJS(cubeLayoutParame)).length > 0;
    }

    return (
      <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@9w4z9t`}
        title={title}
        icon="icon-coms-blog"
        iconBgcolor="#6d3cf7"
        style={{width: 760, height: 500}}
        visible={showPreview}
        moreBtn={{collectParams: collectParams}}
        onCancel={this.doCancel}
        hasScroll
      >
        <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@7jmfta`}
          collectParams={{collectParams}}
        >

          <div className="blogEcmeTemplate">
            {cubeFlags?(CubeLayout({cubeLayoutParame,"callback":this.initCallBack,"getCardStorefun":getCardStorefun})):""}
          </div>

          {!cubeFlags ?  <div className="cke_editable_blog"  style={{padding: '15px 10px'}} dangerouslySetInnerHTML={{__html: richTextValue}}></div>:""}
        </WeaRightMenu>
      </WeaDialog>
    )
  }
}